<template>
	<view class="rent_wrapper">
		<view class="content">
			<view class="input">
				<u--text text="租金" size="16" lineHeight="28" bold></u--text>
				<view class="input_i">
					<u--input placeholder="请输入" border="surround" v-model.trim="rentForm.start" type='number'
						size="mini" @input="changeMoney"></u--input>
				</view>
				<view class="" style="margin: 0 20rpx;">
					-
				</view>
				<view class="input_i">
					<u--input placeholder="请输入" border="surround" v-model.trim="rentForm.end" type='number'
						@input="changeMoney"></u--input>
				</view>
			</view>
			<view class="tag_wrp">
				<view class="item" v-for="(item, index) in rentList" :key="index">
					<view :class="['label',  rentalRange == `${item.start}-${item.end}` ? 'activ_change_color' : ''  ]"
						@click="activeMoney(item)">
						{{ item.start + ' - ' + item.end }}
					</view>
				</view>
			</view>

		</view>
		<u--text text="排序" size="16" lineHeight="28" bold style="margin-top: 20rpx;"></u--text>
		<view class="content">
			<view class="tag_wrp">
				<view class="item" v-for="(item, index) in sortList" :key="index">
					<view :class="['label', curSort === item.id ? 'activ_change_color' : ''  ]"
						@click="changeSort(item)">
						{{ item.name}}
					</view>
				</view>
			</view>
		</view>
		<view class="btn_wrp">
			<view class="btn">
				<u-button ripple @click="rentReset">重置</u-button>
			</view>
			<view class="btn">
				<u-button color="rgb(240, 90, 35)" ripple @click="rentSubmit">确定</u-button>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
   
	export default {
		data() {
			return {
				rentForm: this.$store.state.rentFilter.rentForm,
				curSort: this.$store.state.rentFilter.curSort,
				rentalRange: this.$store.state.rentFilter.rentalRange,
				rentList: JSON.parse(uni.getStorageSync('houseFilter')).rentList,
				sortList: JSON.parse(uni.getStorageSync('houseFilter')).sortList,
				isDisabled: this.$store.state.rentFilter.isDisabled
			}
		},
		methods: {
		 
			changeSort(item) {
				this.curSort = item.id
				this.$store.commit('changeCurSort', item.id)
				// console.log(item);
			},
			changeMoney() {

				if (this.rentForm.start == "" && this.rentForm.end == "") {
					this.rentalRange = `${this.rentForm.start} - ${this.rentForm.end}`;
					this.$store.commit('changerentalRange', `${this.rentForm.start} - ${this.rentForm.end}`)
					this.isDisabled = true	
					this.$store.commit('changeDisabled', true)
				} else {
					this.isDisabled = false
					this.rentalRange = ""
					this.$store.commit('changeDisabled', false)
					this.$store.commit('clearRentalRange')
					 
				}
			},

			activeMoney(item) {
				
				if (this.isDisabled) {
					this.rentalRange = `${item.start}-${item.end}`;
					this.$store.commit('changerentalRange', `${item.start}-${item.end}`)
				}
				
				
			},
			rentReset() {
				this.$store.commit('clearRentalRange')	
				this.rentForm = {
					start: '',
					end: ''
				}
				this.rentalRange = ""
				this.curSort = ''
				
				this.$emit('result')
			},

			rentSubmit() {
				var _index = this.rentalRange.indexOf('-');
				this.showRent = false;
				this.$emit("change", {
					start: this.rentForm.start || this.rentalRange.substr(0, _index),
					end: this.rentForm.end || this.rentalRange.substr(_index + 1, this.rentalRange.length),
					sort: this.curSort
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.rent_wrapper {
		// width: 80%;
		padding: 30rpx;
		margin-top: 30rpx;

		.content {
			.input {

				display: flex;
				justify-content: flex-start;
				align-items: center;
				padding: 10rpx 0;


				.input_i {
					width: 200rpx;
					height: 70rpx;

				}
			}

			.tag_wrp {
				display: flex;
				flex-wrap: wrap;

				.item {
					flex-basis: 100%;
					max-width: calc(100% / 3);
					flex-grow: 1;

					.label {
						width: 80%;
						height: 50rpx;
						line-height: 50rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						font-size: 25rpx;
						margin: 0 10%;
						color: rgb(102, 102, 102);
						background: rgba(115, 110, 110, 0.07);
						margin-top: 20rpx;
					}
				}
			}



		}

		.btn_wrp {
			// padding: 20rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;
			margin: 20rpx 0;
			height: 100rpx;

			.btn {
				margin: 0 10rpx;
				flex: 1;
			}
		}

		.activ_change_color {
			background-color: rgb(240, 90, 35) !important;
			color: #fff !important;
		}
	}
</style>